package net.mingsoft.dashboard.action.web;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import net.mingsoft.base.entity.ResultData;
import net.mingsoft.basic.core.SessionContext;
import net.mingsoft.dashboard.action.q.dashboard.OperateQuery;
import net.mingsoft.dashboard.action.r.FileLogStatisticsResponse;
import net.mingsoft.document.action.r.statistic.FileStatisticResponse;
import net.mingsoft.document.biz.FileStatisticsBiz;
import net.mingsoft.message_center.action.r.MessageResponse;
import net.mingsoft.message_center.biz.MessageBiz;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author gengfa
 * @date 22/01/25
 */
@Api(value = "我的主页", tags = {"工作台-我的主页"})
@Controller("WebDashboardAction")
@RequestMapping("/${ms.manager.path}/dashboard")
public class DashboardAction {

    @Resource
    FileStatisticsBiz fileStatisticsBiz;

    @Resource
    MessageBiz messageBiz;

    @ApiOperation(value = "文档数量统计")
    @GetMapping(value = "/statistics/document/count")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "success", response = FileStatisticResponse.class)
    })
    @ResponseBody
    public ResultData documentCount() {
        List<FileStatisticResponse> responses = fileStatisticsBiz.fileCountGroupByType();
        return ResultData.build().success(responses);
    }

    @ApiOperation(value = "文档操作次数统计")
    @PostMapping(value = "/statistics/operate/count")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "success", response = FileLogStatisticsResponse.class)
    })
    @ResponseBody
    public ResultData operateCount(@RequestBody OperateQuery query) {
        FileLogStatisticsResponse res = fileStatisticsBiz.fileLogCountGroupByType(query);
        return ResultData.build().success(res);
    }

    @ApiOperation(value = "消息中心")
    @GetMapping(value = "/message/center/list")
    @ResponseBody
    public ResultData messageList() {
        List<MessageResponse> list = messageBiz.list(SessionContext.session().getIntId());
        return ResultData.build().success(list);
    }
}
